#ifndef _GVIENTRY_H
#define _GVIENTRY_H


/*
 * Group Variable-length Integer
 *
 * 见WSDM09-keynote.pdf第63页
 *
 * Version 0.2
 *
 */
#include <string>
namespace luolei { namespace hit { namespace cir { namespace se { namespace gvi {

    static const char GVIENTRY[256][4] =
    {
        {0,0,0,0},
        {0,0,0,1},
        {0,0,0,2},
        {0,0,0,3},
        {0,0,1,0},
        {0,0,1,1},
        {0,0,1,2},
        {0,0,1,3},
        {0,0,2,0},
        {0,0,2,1},
        {0,0,2,2},
        {0,0,2,3},
        {0,0,3,0},
        {0,0,3,1},
        {0,0,3,2},
        {0,0,3,3},
        {0,1,0,0},
        {0,1,0,1},
        {0,1,0,2},
        {0,1,0,3},
        {0,1,1,0},
        {0,1,1,1},
        {0,1,1,2},
        {0,1,1,3},
        {0,1,2,0},
        {0,1,2,1},
        {0,1,2,2},
        {0,1,2,3},
        {0,1,3,0},
        {0,1,3,1},
        {0,1,3,2},
        {0,1,3,3},
        {0,2,0,0},
        {0,2,0,1},
        {0,2,0,2},
        {0,2,0,3},
        {0,2,1,0},
        {0,2,1,1},
        {0,2,1,2},
        {0,2,1,3},
        {0,2,2,0},
        {0,2,2,1},
        {0,2,2,2},
        {0,2,2,3},
        {0,2,3,0},
        {0,2,3,1},
        {0,2,3,2},
        {0,2,3,3},
        {0,3,0,0},
        {0,3,0,1},
        {0,3,0,2},
        {0,3,0,3},
        {0,3,1,0},
        {0,3,1,1},
        {0,3,1,2},
        {0,3,1,3},
        {0,3,2,0},
        {0,3,2,1},
        {0,3,2,2},
        {0,3,2,3},
        {0,3,3,0},
        {0,3,3,1},
        {0,3,3,2},
        {0,3,3,3},
        {1,0,0,0},
        {1,0,0,1},
        {1,0,0,2},
        {1,0,0,3},
        {1,0,1,0},
        {1,0,1,1},
        {1,0,1,2},
        {1,0,1,3},
        {1,0,2,0},
        {1,0,2,1},
        {1,0,2,2},
        {1,0,2,3},
        {1,0,3,0},
        {1,0,3,1},
        {1,0,3,2},
        {1,0,3,3},
        {1,1,0,0},
        {1,1,0,1},
        {1,1,0,2},
        {1,1,0,3},
        {1,1,1,0},
        {1,1,1,1},
        {1,1,1,2},
        {1,1,1,3},
        {1,1,2,0},
        {1,1,2,1},
        {1,1,2,2},
        {1,1,2,3},
        {1,1,3,0},
        {1,1,3,1},
        {1,1,3,2},
        {1,1,3,3},
        {1,2,0,0},
        {1,2,0,1},
        {1,2,0,2},
        {1,2,0,3},
        {1,2,1,0},
        {1,2,1,1},
        {1,2,1,2},
        {1,2,1,3},
        {1,2,2,0},
        {1,2,2,1},
        {1,2,2,2},
        {1,2,2,3},
        {1,2,3,0},
        {1,2,3,1},
        {1,2,3,2},
        {1,2,3,3},
        {1,3,0,0},
        {1,3,0,1},
        {1,3,0,2},
        {1,3,0,3},
        {1,3,1,0},
        {1,3,1,1},
        {1,3,1,2},
        {1,3,1,3},
        {1,3,2,0},
        {1,3,2,1},
        {1,3,2,2},
        {1,3,2,3},
        {1,3,3,0},
        {1,3,3,1},
        {1,3,3,2},
        {1,3,3,3},
        {2,0,0,0},
        {2,0,0,1},
        {2,0,0,2},
        {2,0,0,3},
        {2,0,1,0},
        {2,0,1,1},
        {2,0,1,2},
        {2,0,1,3},
        {2,0,2,0},
        {2,0,2,1},
        {2,0,2,2},
        {2,0,2,3},
        {2,0,3,0},
        {2,0,3,1},
        {2,0,3,2},
        {2,0,3,3},
        {2,1,0,0},
        {2,1,0,1},
        {2,1,0,2},
        {2,1,0,3},
        {2,1,1,0},
        {2,1,1,1},
        {2,1,1,2},
        {2,1,1,3},
        {2,1,2,0},
        {2,1,2,1},
        {2,1,2,2},
        {2,1,2,3},
        {2,1,3,0},
        {2,1,3,1},
        {2,1,3,2},
        {2,1,3,3},
        {2,2,0,0},
        {2,2,0,1},
        {2,2,0,2},
        {2,2,0,3},
        {2,2,1,0},
        {2,2,1,1},
        {2,2,1,2},
        {2,2,1,3},
        {2,2,2,0},
        {2,2,2,1},
        {2,2,2,2},
        {2,2,2,3},
        {2,2,3,0},
        {2,2,3,1},
        {2,2,3,2},
        {2,2,3,3},
        {2,3,0,0},
        {2,3,0,1},
        {2,3,0,2},
        {2,3,0,3},
        {2,3,1,0},
        {2,3,1,1},
        {2,3,1,2},
        {2,3,1,3},
        {2,3,2,0},
        {2,3,2,1},
        {2,3,2,2},
        {2,3,2,3},
        {2,3,3,0},
        {2,3,3,1},
        {2,3,3,2},
        {2,3,3,3},
        {3,0,0,0},
        {3,0,0,1},
        {3,0,0,2},
        {3,0,0,3},
        {3,0,1,0},
        {3,0,1,1},
        {3,0,1,2},
        {3,0,1,3},
        {3,0,2,0},
        {3,0,2,1},
        {3,0,2,2},
        {3,0,2,3},
        {3,0,3,0},
        {3,0,3,1},
        {3,0,3,2},
        {3,0,3,3},
        {3,1,0,0},
        {3,1,0,1},
        {3,1,0,2},
        {3,1,0,3},
        {3,1,1,0},
        {3,1,1,1},
        {3,1,1,2},
        {3,1,1,3},
        {3,1,2,0},
        {3,1,2,1},
        {3,1,2,2},
        {3,1,2,3},
        {3,1,3,0},
        {3,1,3,1},
        {3,1,3,2},
        {3,1,3,3},
        {3,2,0,0},
        {3,2,0,1},
        {3,2,0,2},
        {3,2,0,3},
        {3,2,1,0},
        {3,2,1,1},
        {3,2,1,2},
        {3,2,1,3},
        {3,2,2,0},
        {3,2,2,1},
        {3,2,2,2},
        {3,2,2,3},
        {3,2,3,0},
        {3,2,3,1},
        {3,2,3,2},
        {3,2,3,3},
        {3,3,0,0},
        {3,3,0,1},
        {3,3,0,2},
        {3,3,0,3},
        {3,3,1,0},
        {3,3,1,1},
        {3,3,1,2},
        {3,3,1,3},
        {3,3,2,0},
        {3,3,2,1},
        {3,3,2,2},
        {3,3,2,3},
        {3,3,3,0},
        {3,3,3,1},
        {3,3,3,2},
        {3,3,3,3},
    };

    const static unsigned int MASKS[4] = {0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};

   /*
     * 读入四个unsigned int值到data[]中
     *
     * 参数说明：
     *  data：存放读出的4个正整数
     *  buf：四个正整数的GVI bytes流形式
     *
     * 返回值：
     *  从buf中读到的char个数(四个数一个tag共用了多少char)
     */
    int readGVInt(unsigned int* data, const unsigned char* buf);

    /*
     * 把正整数数组写成GVI bytes流，可能会抛出MyException异常。
     * 
     * 参数说明：
     *  buf：保存写入的bytes流的数组
     *  data：待写成bytes流的正整数数组
     *  size：默认为写入4个正整数，如果size<4，则缺少的正整数按0处理，如果size>4抛出MyException异常
     *
     * 返回值：
     *  返回读到buf中的char的个数
     */
    int writeGVInt(unsigned char *buf, const unsigned int *data, int size = 4);

}}}}}//namespace luolei::hit::cir::se::gvi

#endif//_GVIENTRY_H
